<?php

class Wmp_Controller_Plugin_Translations extends Zend_Controller_Plugin_Abstract
{    
    
    /**
     *
     * @param Zend_Controller_Request_Abstract $request
     */
    public function preDispatch(Zend_Controller_Request_Abstract $request)
    {   
    	$config = zend_registry::get('config');
    	     	
    	$language = $request->getParam("language", null);
		$languageList = explode(',',$config->languageList);
    	if(in_array($language,$languageList))
        	$locale = new Zend_Locale($config->localCodes->$language);
        else 
        	$locale = new Zend_Locale($config->defaultLanguage);
       
        Zend_Translate::setCache(zend_registry::get('cache'));        
		Zend_Registry::set('Zend_Locale', $locale);  
		
		//les fichiers doivent se terminer pas _fr.mo (fr représent le code langue)
		$translate = new Zend_Translate('gettext',
                                		$config->path->languages->dir,
                                		null,
                               			 array('scan' =>
                                      		Zend_Translate::LOCALE_FILENAME)
                                		);        
        $translate->setLocale($locale); 
        $userdata = new Zend_Session_Namespace('userdata'); 
        $userdata->local = $locale;  //URGENT : voir où j'ai utilisé ça et si possible utiliser plutot l'objet request    
        Zend_Registry::set('Zend_Translate', $translate);        
        return;        
    }    
}